import App from './App'
import uviewPlus from '@/uni_modules/uview-plus'
import {initRequest} from './util/request/index'
import {
	createSSRApp
} from 'vue'
import * as Pinia from 'pinia'
import { Tracker } from '@/util/tracker'

export function createApp() {
	const app = createSSRApp(App)
	// 引入请求封装
	initRequest(app)
	// 引入uview
	app.use(uviewPlus)
	
	const store = Pinia.createPinia()
	app.use(store)
	
	// 初始化埋点系统
	const tracker = new Tracker()
	tracker.init()
	// 捕获uni-app全局错误
	uni.onError((error) => {
		console.log('捕获uni-app全局错误',error)
	    tracker.trackError(error, { type: 'UNI_APP_ERROR' })
	})
	  
	// 挂载到全局属性
	app.config.globalProperties.$tracker = tracker
	uni.$tracker = tracker
	
	return {
		app,
		Pinia
	}
}

